﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Reports
{
    public partial class report_student_teacher : System.Web.UI.Page
    {
        public int early = 0, late = 0, absent_yes = 0, absent_no = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["id"]);
            DateTime date = DateTime.Parse(Request.QueryString["date"]);
            int type = int.Parse(Request.QueryString["type"]);
  
            foreach (TblClass cls in new TblClassController().FetchAll().Where(x => x.Teacher == id && x.Active == true))
            {
                if (type == 1)
                {
                    foreach (TblCheckUser chk_user in new TblCheckUserController().FetchAll().Where(x => x.ClassX == cls.Id && DateTime.Parse(x.DateX.ToString()).Date == date.Date))
                    {
                        if (chk_user.Early == true)
                            early++;
                        if (chk_user.Late == true)
                            late++;
                        if (chk_user.AbsentYes == true)
                            absent_yes++;
                        if (chk_user.AbsentNo == true)
                            absent_no++;
                    }
                }
                if (type == 2)
                {
                    foreach (TblCheckUser chk_user in new TblCheckUserController().FetchAll().Where(x => x.ClassX == cls.Id && DateTime.Parse(x.DateX.ToString()).Month == date.Month && DateTime.Parse(x.DateX.ToString()).Year == date.Year))
                    {
                        if (chk_user.Early == true)
                            early++;
                        if (chk_user.Late == true)
                            late++;
                        if (chk_user.AbsentYes == true)
                            absent_yes++;
                        if (chk_user.AbsentNo == true)
                            absent_no++;
                    }
                }
                if (type == 3)
                {
                    foreach (TblCheckUser chk_user in new TblCheckUserController().FetchAll().Where(x => x.ClassX == cls.Id && DateTime.Parse(x.DateX.ToString()).Year == date.Year))
                    {
                        if (chk_user.Early == true)
                            early++;
                        if (chk_user.Late == true)
                            late++;
                        if (chk_user.AbsentYes == true)
                            absent_yes++;
                        if (chk_user.AbsentNo == true)
                            absent_no++;
                    }
                }
            }
        }
    }
}